package com.cosina.game.crystallight.ui.battle.drawadapter;

import android.graphics.Bitmap;
import android.graphics.Canvas;

import com.cosina.game.crystallight.util.World;

public abstract class BaseLayer implements Layer{

	private Bitmap cache;
	private final int width;
	private final int height;
	
	public BaseLayer(){
		this(World.SCREEN_WIDTH, World.SCREEN_HEIGHT);
	}
	public BaseLayer(int width, int height){
		this.width = width;
		this.height = height;
	}
	
	@Override
	public final Bitmap getLayer() {
		if (null == cache ) {
			cache = Bitmap.createBitmap(width,
					height, Bitmap.Config.ARGB_8888);
			Canvas canvas = new Canvas(cache);
			draw(canvas);
			cache = Bitmap.createBitmap(cache);
		}
		return cache;
	}
	
	protected abstract void draw(Canvas canvas);
}
